package com.library.service;

import java.util.List;

import com.library.dao.ICommonDAO;
import com.library.model.Userinfo;

public class UserService {
	private ICommonDAO commonDao;

	public ICommonDAO getCommonDao() {
		return commonDao;
	}

	public void setCommonDao(ICommonDAO commonDao) {
		this.commonDao = commonDao;
	}
	
	public Userinfo getUser(String username,String userpwd){
		String hql = "from Userinfo u where u.username = ? and u.userpwd = ?";
		Object[] args = new Object[]{username,userpwd};
		List list = commonDao.list(hql,args);
		if(list.size()!=0&&list!=null){
			Userinfo user  = (Userinfo) list.get(0);
			return user;
		}
		return null;
	}
	
	public Userinfo checkUser(String username,String userpwd,int roleid){
		String hql = "from Userinfo u where u.username = ? and u.userpwd = ? and u.roleinfo.roleid = ?";
		Object[] args = new Object[]{username,userpwd,roleid};
		List list = commonDao.list(hql,args);
		if(list.size()!=0&&list!=null){
			Userinfo user  = (Userinfo) list.get(0);
			return user;
		}
		return null;
	}
}
